<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="承灾体名称" prop="cztName">
        <el-input
          v-model="queryParams.cztName"
          placeholder="请输入承灾体名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="填报人" prop="personsTianbao">
        <el-input
          v-model="queryParams.personsTianbao"
          placeholder="请输入填报人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="机构详细地址" prop="address">
        <el-input
          v-model="queryParams.address"
          placeholder="请输入机构详细地址"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="承灾体中类" prop="cztMiddle">
        <el-input
          v-model="queryParams.cztMiddle"
          placeholder="请输入承灾体中类"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="承灾体小类" prop="cztSmall">
        <el-input
          v-model="queryParams.cztSmall"
          placeholder="请输入承灾体小类"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:ybyj:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:ybyj:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:ybyj:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:ybyj:export']"
        >导出</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-upload :action='`${this.env.VUE_APP_BASE_API}/system/ybyj/import" @on-success="handleQuery`'> 
          <el-button size="small" type="primary">导入</el-button>
        </el-upload>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="ybyjList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="id" align="center" prop="id" v-if="false"/>
      <el-table-column label="填报人" align="center" prop="personsTianbao" />
      <el-table-column label="机构详细地址" align="center" prop="address" />
      <el-table-column label="曾经遭受过的自然灾害类型" align="center" prop="cszLeixing" />
      <el-table-column label="曾经遭受过的自然灾害类型——其他说明" align="center" prop="cszShuoming" />
      <el-table-column label="承灾体大类" align="center" prop="cztBig" />
      <el-table-column label="承灾体中类" align="center" prop="cztMiddle" />
      <el-table-column label="承灾体小类" align="center" prop="cztSmall" />
      <el-table-column label="固定资产合计" align="center" prop="gdzcHeji" />
      <el-table-column label="固定资产原值" align="center" prop="gdzcYuanzhi" />
      <el-table-column label="市州" align="center" prop="shizhou" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:ybyj:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:ybyj:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改承灾体基础对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="900px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="300px">
        <el-form-item label="承灾体名称" prop="cztName">
          <el-input v-model="form.cztName" placeholder="请输入承灾体名称" />
        </el-form-item>
        <el-form-item label="填报人" prop="personsTianbao">
          <el-input v-model="form.personsTianbao" placeholder="请输入填报人" />
        </el-form-item>
        <el-form-item label="机构详细地址" prop="address">
          <el-input v-model="form.address" placeholder="请输入机构详细地址" />
        </el-form-item>
        <el-form-item label="曾经遭受过的自然灾害类型" prop="cszLeixing">
          <el-input v-model="form.cszLeixing" placeholder="请输入曾经遭受过的自然灾害类型" />
        </el-form-item>
        <el-form-item label="曾经遭受过的自然灾害类型——其他说明" prop="cszShuoming">
          <el-input v-model="form.cszShuoming" placeholder="请输入曾经遭受过的自然灾害类型——其他说明" />
        </el-form-item>
        <el-form-item label="承灾体大类" prop="cztBig">
          <el-input v-model="form.cztBig" placeholder="请输入承灾体大类" />
        </el-form-item>
        <el-form-item label="承灾体中类" prop="cztMiddle">
          <el-input v-model="form.cztMiddle" placeholder="请输入承灾体中类" />
        </el-form-item>
        <el-form-item label="承灾体小类" prop="cztSmall">
          <el-input v-model="form.cztSmall" placeholder="请输入承灾体小类" />
        </el-form-item>
        <el-form-item label="固定资产合计" prop="gdzcHeji">
          <el-input v-model="form.gdzcHeji" placeholder="请输入固定资产合计" />
        </el-form-item>
        <el-form-item label="固定资产原值" prop="gdzcYuanzhi">
          <el-input v-model="form.gdzcYuanzhi" placeholder="请输入固定资产原值" />
        </el-form-item>
        <el-form-item label="应急供电能力" prop="gongdian">
          <el-input v-model="form.gongdian" placeholder="请输入应急供电能力" />
        </el-form-item>
        <el-form-item label="供暖方式" prop="gongnuan">
          <el-input v-model="form.gongnuan" placeholder="请输入供暖方式" />
        </el-form-item>
        <el-form-item label="供水方式" prop="gongshui">
          <el-input v-model="form.gongshui" placeholder="请输入供水方式" />
        </el-form-item>
        <el-form-item label="机构名称" prop="jgName">
          <el-input v-model="form.jgName" placeholder="请输入机构名称" />
        </el-form-item>
        <el-form-item label="几何信息" prop="jihe">
          <el-input v-model="form.jihe" placeholder="请输入几何信息" />
        </el-form-item>
        <el-form-item label="建筑面积" prop="mianjiJianzhu">
          <el-input v-model="form.mianjiJianzhu" placeholder="请输入建筑面积" />
        </el-form-item>
        <el-form-item label="占地面积" prop="mianjiZhandi">
          <el-input v-model="form.mianjiZhandi" placeholder="请输入占地面积" />
        </el-form-item>
        <el-form-item label="安全保卫人员数量" prop="personsAqbw">
          <el-input v-model="form.personsAqbw" placeholder="请输入安全保卫人员数量" />
        </el-form-item>
        <el-form-item label="操作人员" prop="personsCaozuo">
          <el-input v-model="form.personsCaozuo" placeholder="请输入操作人员" />
        </el-form-item>
        <el-form-item label="录入人" prop="personsLuru">
          <el-input v-model="form.personsLuru" placeholder="请输入录入人" />
        </el-form-item>
        <el-form-item label="填报人电话" prop="personsTianbaoPhone">
          <el-input v-model="form.personsTianbaoPhone" placeholder="请输入填报人电话" />
        </el-form-item>
        <el-form-item label="责任人电话" prop="personsZrrPhone">
          <el-input v-model="form.personsZrrPhone" placeholder="请输入责任人电话" />
        </el-form-item>
        <el-form-item label="责任人" prop="perssonsZrr">
          <el-input v-model="form.perssonsZrr" placeholder="请输入责任人" />
        </el-form-item>
        <el-form-item label="区县" prop="quxian">
          <el-input v-model="form.quxian" placeholder="请输入区县" />
        </el-form-item>
        <el-form-item label="地图信息" prop="shap">
          <el-input v-model="form.shap" placeholder="请输入地图信息" />
        </el-form-item>
        <el-form-item label="市州" prop="shizhou">
          <el-input v-model="form.shizhou" placeholder="请输入市州" />
        </el-form-item>
        <el-form-item label="录入时间" prop="timeLuru">
          <el-input v-model="form.timeLuru" placeholder="请输入录入时间" />
        </el-form-item>
        <el-form-item label="应急通信保障方式" prop="tongxin">
          <el-input v-model="form.tongxin" placeholder="请输入应急通信保障方式" />
        </el-form-item>
        <el-form-item label="图例id" prop="tuliId">
          <el-input v-model="form.tuliId" placeholder="请输入图例id" />
        </el-form-item>
        <el-form-item label="行政区划代码" prop="tyQuhuaDaima">
          <el-input v-model="form.tyQuhuaDaima" placeholder="请输入行政区划代码" />
        </el-form-item>
        <el-form-item label="统一社会信用代码" prop="tyShxyDaima">
          <el-input v-model="form.tyShxyDaima" placeholder="请输入统一社会信用代码" />
        </el-form-item>
        <el-form-item label="最后修改时间" prop="updateFinallyTime">
          <el-input v-model="form.updateFinallyTime" placeholder="请输入最后修改时间" />
        </el-form-item>
        <el-form-item label="详情" prop="xiangqing">
          <el-input v-model="form.xiangqing" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="乡镇" prop="xiangzhen">
          <el-input v-model="form.xiangzhen" placeholder="请输入乡镇" />
        </el-form-item>
        <el-form-item label="是否删除" prop="ynDelete">
          <el-input v-model="form.ynDelete" placeholder="请输入是否删除" />
        </el-form-item>
        <el-form-item label="是否修改" prop="ynUpdate">
          <el-input v-model="form.ynUpdate" placeholder="请输入是否修改" />
        </el-form-item>
        <el-form-item label="预案id" prop="yuanId">
          <el-input v-model="form.yuanId" placeholder="请输入预案id" />
        </el-form-item>
        <el-form-item label="已有自然灾害应急预案类型" prop="yuanLeixing">
          <el-input v-model="form.yuanLeixing" placeholder="请输入已有自然灾害应急预案类型" />
        </el-form-item>
        <el-form-item label="已有自然灾害应急预案类型——其他说明" prop="yuanShuoming">
          <el-input v-model="form.yuanShuoming" placeholder="请输入已有自然灾害应急预案类型——其他说明" />
        </el-form-item>
        <el-form-item label="尚未领取统一社会信用代码的填原组织机构代码" prop="yuanShxyDaima">
          <el-input v-model="form.yuanShxyDaima" placeholder="请输入尚未领取统一社会信用代码的填原组织机构代码" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button :loading="buttonLoading" type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listYbyj, getYbyj, delYbyj, addYbyj, updateYbyj } from "@/api/system/ybyj";
import DynamicSelect from "@/components/DynamicSelect";
import AutoCompute from "@/components/AutoCompute";

export default {
  name: "Ybyj",
  components: { DynamicSelect, AutoCompute },
  data() {
    return {
      // 按钮loading
      buttonLoading: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 承灾体基础表格数据
      ybyjList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        cztName: undefined,
        personsTianbao: undefined,
        address: undefined,
        cztMiddle: undefined,
        cztSmall: undefined,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        cztName: [
          { required: true, message: "承灾体名称不能为空", trigger: "blur" }
        ],
        personsTianbao: [
          { required: true, message: "填报人不能为空", trigger: "blur" }
        ],
        address: [
          { required: true, message: "机构详细地址不能为空", trigger: "blur" }
        ],
        gdzcHeji: [
          { required: true, message: "固定资产合计不能为空", trigger: "blur" }
        ],
        gdzcYuanzhi: [
          { required: true, message: "固定资产原值不能为空", trigger: "blur" }
        ],
        gongdian: [
          { required: true, message: "应急供电能力不能为空", trigger: "blur" }
        ],
        gongnuan: [
          { required: true, message: "供暖方式不能为空", trigger: "blur" }
        ],
        gongshui: [
          { required: true, message: "供水方式不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询承灾体基础列表 */
    getList() {
      this.loading = true;
      listYbyj(this.queryParams).then(response => {
       Promise.all(
                [
                ]
              ).then(() => {
                this.ybyjList = response.rows;
                this.total = response.total;
                this.loading = false;
            })
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        createBy: undefined,
        createTime: undefined,
        updateBy: undefined,
        updateTime: undefined,
        cztName: undefined,
        personsTianbao: undefined,
        address: undefined,
        cszLeixing: undefined,
        cszShuoming: undefined,
        cztId: undefined,
        cztBig: undefined,
        cztMiddle: undefined,
        cztSmall: undefined,
        gdzcHeji: undefined,
        gdzcYuanzhi: undefined,
        gongdian: undefined,
        gongnuan: undefined,
        gongshui: undefined,
        jgName: undefined,
        jihe: undefined,
        mianjiJianzhu: undefined,
        mianjiZhandi: undefined,
        personsAqbw: undefined,
        personsCaozuo: undefined,
        personsLuru: undefined,
        personsTianbaoPhone: undefined,
        personsZrrPhone: undefined,
        perssonsZrr: undefined,
        quxian: undefined,
        shap: undefined,
        shizhou: undefined,
        timeLuru: undefined,
        tongxin: undefined,
        tuliId: undefined,
        tyQuhuaDaima: undefined,
        tyShxyDaima: undefined,
        updateFinallyTime: undefined,
        xiangqing: undefined,
        xiangzhen: undefined,
        ynDelete: undefined,
        ynUpdate: undefined,
        yuanId: undefined,
        yuanLeixing: undefined,
        yuanShuoming: undefined,
        yuanShxyDaima: undefined
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加承灾体基础";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.loading = true;
      this.reset();
      const id = row.id || this.ids
      getYbyj(id).then(response => {
        this.loading = false;
        this.form = response.data;
        this.open = true;
        this.title = "修改承灾体基础";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          this.buttonLoading = true;
          if (this.form.id != null) {
            updateYbyj(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            }).finally(() => {
              this.buttonLoading = false;
            });
          } else {
            addYbyj(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            }).finally(() => {
              this.buttonLoading = false;
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除').then(() => {
        this.loading = true;
        return delYbyj(ids);
      }).then(() => {
        this.loading = false;
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {
      }).finally(() => {
        this.loading = false;
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/ybyj/export', {
        ...this.queryParams
      }, `ybyj_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
